package com.company.ems.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class VerifyUserUtil {
    
    public static void main(String[] args) {
        System.out.println("验证用户信息...");
        
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        
        try {
            conn = DatabaseUtil.getConnection();
            String sql = "SELECT id, username, password FROM users WHERE username = ?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, "admin");
            
            rs = pstmt.executeQuery();
            
            if (rs.next()) {
                int id = rs.getInt("id");
                String username = rs.getString("username");
                String password = rs.getString("password");
                
                System.out.println("用户信息验证成功：");
                System.out.println("ID: " + id);
                System.out.println("用户名: " + username);
                System.out.println("密码: " + password);
            } else {
                System.out.println("✗ 未找到指定用户");
            }
            
        } catch (SQLException e) {
            System.err.println("✗ 数据库操作异常: " + e.getMessage());
            e.printStackTrace();
        } finally {
            DatabaseUtil.closeConnection(conn, pstmt, rs);
        }
    }
}